/* 
用来收集点击的坐标的hook函数
*/
import {ref, onMounted, onBeforeUnmount} from 'vue'

export default function useClickPosition() {
  const x = ref(-1)
    const y = ref(-1)

    const handleClick = (event: MouseEvent) => {
      console.log('click....')
      x.value = event.pageX
      y.value = event.pageY
    };

    // 组件初始显示后调用 => 绑定事件监听
    onMounted(() => { 
      // 给页面绑定点击监听
      document.addEventListener('click', handleClick)
    })

    // 在组件死亡前解绑事件监听
    onBeforeUnmount(() => {
      document.removeEventListener('click', handleClick)
    })


    return {
      x,
      y
    }
}


/* 

{
  default: () => {

  }
}

import xxx from './useClickPosition'
export {default as yyy} from './useClickPosition'


{
  yyy
}
*/